﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BE.DataFramework;
using BE;

namespace BC.DataFramework
{
    public class DataTransactionsBC
    {
        public DataTransactionsBE Create(DataTransactionsBE item)
        {
            try
            {
                if (item == null)
                {
                    throw new BusinessException("Faltan datos.");
                }
                else if (item.iConnectionId == null)
                {
                    throw new BusinessException("La conexion es requerida.");
                }
                else if (string.IsNullOrEmpty(item.sName))
                {
                    throw new BusinessException("El nombre es requerido.");
                }
                else if (string.IsNullOrEmpty(item.sProcedureName))
                {
                    throw new BusinessException("El nombre del procedimiento almacenado es requerido.");
                }

                DataTransactionsBE result = new DataTransactionsBE();
                result = item.Create();

                return result;
            }
            catch (Exception ex)
            {
                throw new AppException("DataTransactionsBC - Create - ", ex);
            }
        }
        public DataTransactionsBE Update(DataTransactionsBE item)
        {
            try
            {
                if (item == null)
                {
                    throw new BusinessException("Faltan datos.");
                }
                else if (item.iDataTransactionId == null)
                {
                    throw new BusinessException("Faltan datos.");
                }
                else if (item.iDataTransactionId < 1)
                {
                    throw new BusinessException("Faltan datos.");
                }
                else if (item.iConnectionId == null)
                {
                    throw new BusinessException("La conexion es requerida.");
                }
                else if (item.iConnectionId < 1)
                {
                    throw new BusinessException("La conexion es requerida.");
                }
                else if (string.IsNullOrEmpty(item.sName))
                {
                    throw new BusinessException("El nombre es requerido.");
                }
                else if (string.IsNullOrEmpty(item.sProcedureName))
                {
                    throw new BusinessException("El nombre del procedimiento almacenado es requerido.");
                }

                DataTransactionsBE result = new DataTransactionsBE();
                result = item.Update();

                return result;
            }
            catch (Exception ex)
            {
                throw new AppException("DataTransactionsBC - Create - ", ex);
            }
        }
        public bool Delete(DataTransactionsBE item)
        {
            try
            {
                if (item == null)
                {
                    throw new BusinessException("Faltan datos.");
                }
                else if (item.iDataTransactionId == null)
                {
                    throw new BusinessException("Faltan datos.");
                }
                else if (item.iDataTransactionId < 1)
                {
                    throw new BusinessException("Faltan datos.");
                }

                return item.Delete() > 0 ? true : false;
            }
            catch (Exception ex)
            {
                throw new AppException("DataTransactionsBC - Delete - ", ex);
            }
        }
        public List<DataTransactionsBE> Select(DataTransactionsBE item)
        {
            try
            {
                if (item == null)
                {
                    throw new BusinessException("Faltan datos");
                }

                return item.Select();
            }
            catch (Exception ex)
            {
                throw new AppException("DataTransactionsBC - Select - ", ex);
            }
        }
    }
}
